package main

import (
	"fmt"
	"sync"
)

type channels struct {
	in   chan int
	done func()
}

func doWork(id int, chs channels) {
	go func() {
		for {
			fmt.Printf("id=%d,num=%c \n", id, <-chs.in)
			chs.done()
		}
	}()
}

func createWorker(id int, group *sync.WaitGroup) chan int {
	in := make(chan int)
	chs := channels{
		in,
		func() {
			group.Done()
		},
	}
	doWork(id, chs)
	return in
}

func sendDemo() {
	chs := [10]chan int{}
	group := sync.WaitGroup{}
	group.Add(20)
	for i := 0; i < 10; i++ {
		chs[i] = createWorker(i, &group)
	}
	//channel取值是阻塞的
	for i, ch := range chs {
		ch <- 'a' + i
	}
	for i, ch := range chs {
		ch <- 'A' + i
	}
	group.Wait()
}

func main() {
	sendDemo()
}
